package cn.xxc.system.controller;

import cn.xxc.basic.util.AjaxResult;
import cn.xxc.basic.util.PageList;

import cn.xxc.system.domain.Systemdictionarydetail;
import cn.xxc.system.mapper.SystemdictionarydetailMapper;
import cn.xxc.system.query.SystemdictionarydetailQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarydetail")
public class SystemdictionarydetailController {
    @Autowired
    private SystemdictionarydetailMapper systemdictionarydetailMapper;




    @GetMapping
    private List<Systemdictionarydetail> findAll(){
        return systemdictionarydetailMapper.loadAll();
    }

    @GetMapping("/{id}")
    public Systemdictionarydetail findOne(@PathVariable("id") Long id ){
        return systemdictionarydetailMapper.loadByid(id);
    }

    @PutMapping
    public AjaxResult save(@RequestBody Systemdictionarydetail systemdictionarydetail){
        try {
            if (systemdictionarydetail.getId()==null){
                systemdictionarydetailMapper.save(systemdictionarydetail);
            }else {
                systemdictionarydetailMapper.update(systemdictionarydetail);
            }
            return new AjaxResult();
        }catch (Exception e){
            return new AjaxResult(false, "系统繁忙，请重试！！");
        }
    }

    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable("id")Long id){
        try {
            systemdictionarydetailMapper.del(id);
            return new AjaxResult();
        }catch (Exception e){
            return new AjaxResult(false, "系统繁忙，请重试！！");
        }
    }

    @PostMapping
    public PageList<Systemdictionarydetail> queryList(@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery){
        try {
            Integer totals=systemdictionarydetailMapper.queryCount(systemdictionarydetailQuery);
            List<Systemdictionarydetail> data=systemdictionarydetailMapper.queryData(systemdictionarydetailQuery);
            System.out.println(data);
            return new PageList<>(totals,data);
        }catch (Exception e){
            System.out.println(e.getMessage());
            return new PageList<>();
        }
    }

    @PatchMapping
    public AjaxResult patchDel(@RequestBody Long[] ids){
        try {
            systemdictionarydetailMapper.patchDel(ids);
            return new AjaxResult();
        }catch (Exception e){
            return new AjaxResult(false, "系统繁忙，请重试！！");
        }
    }
}


